package com.mq.server.config;

import com.mq.server.constant.MyConstants;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * <h3>partitionjob</h3>
 * <p>Producer</p>
 *
 * @author : hduong
 * @version : 1.0
 * @date : 2019-12-18 21:01
 **/
@Component
public class Producer {

    @Autowired
    private AmqpTemplate amqpTemplate;

    public void send() {
        String sendMsg = "Hi~" + new Date();
        //生产消息到 mq 的虚拟机的 队列 HELLO_QUEUE中
        this.amqpTemplate.convertAndSend(MyConstants.HELLO_QUEUE, sendMsg);
    }


    /**
     * <发送消息>
     * @param msg
     * @date : 2019/12/19 10:44
     * @return : void
     * @author : hduong
     */
    public void send(String msg) {
        String sendMsg = "Hi~" + new Date() + " : " + msg;
        this.amqpTemplate.convertAndSend(MyConstants.HELLO_QUEUE, sendMsg);
    }
}
